package com.dfbz.文件上传;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class serverFTP {
    public static void main(String[] args) throws IOException {
        //开启一个服务器,设置端口
        ServerSocket serverSocket = new ServerSocket(8888);
        //接收客户端传来的数据
        Socket accept = serverSocket.accept();
        System.out.println(accept.getInetAddress().getHostAddress() + "连接成功");
        //字节读取客户端传来的数据
        InputStream inputStream = accept.getInputStream();
        FileOutputStream fos = new FileOutputStream(new File("C:\\Users\\admin\\Desktop\\ftp1.jpg"));
        byte[] data=new byte[1024];
        int len;
        while ((len=inputStream.read(data))!=-1){
            fos.write(data,0,len);
        }
        fos.close();
        serverSocket.close();
    }
}
